/*
** xthreads.c for  in /home/costa_k//rendulocal/cunix/philosophe/epi-philosophes/srcs
** 
** Made by kevin costa
** Login   <costa_k@epitech.net>
** 
** Started on  Wed May  4 16:55:50 2011 kevin costa
** Last update Wed May  4 17:49:59 2011 kevin costa
*/

#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void	xpthread_mutex_init(pthread_mutex_t *mutex,
			    const pthread_mutexattr_t *attr)
{
  int	ret;

  ret = pthread_mutex_init(mutex, attr);
  if (ret != 0)
    {
      write(2, "Error while initializing mutex\n",
	    strlen("Error while initializing mutex\n"));
      exit(EXIT_FAILURE);
    }
}

void	xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
		   void *(*start_routine) (void *), void *arg)
{
  int	ret;

  ret = pthread_create(thread, attr, start_routine, arg);
  if (ret != 0)
    {
      write(2, "Error while opening thread\n", (size_t)27);
      exit(EXIT_FAILURE);
    }
}

void	xpthread_join(pthread_t thread, void **retval)
{
  int	ret;

  ret = pthread_join(thread, retval);
  if (ret != 0)
    {
      write(2, "Could not join thread\n", strlen("Could not join thread\n"));
      exit(EXIT_FAILURE);
    }
}
